<?php

    class Authctrl extends Controller
    {        
        var $view_path;

        function Authctrl()
        {
            parent::Controller();            
            if( !class_exists('CI_Session') )
                $this->load->library('Session');
            if( !class_exists('CI_Database') )
                $this->load->database();
            if( !class_exists('Ram') )
                $this->load->model('Ram');
            if( !class_exists('Rauth') )
                $this->load->library('Rauth');

            
            $this->config->load('rauth_config',TRUE);
            $this->lang->load('rauth');
            $this->view_path    = $this->config->item('templates_path','rauth_config');
            $this->refresh_time = $this->config->item('page_refresh_seconds','rauth_config');
            $this->refresh_url  = $this->config->item('page_refresh_to','rauth_config');
        }

        function request_password_reset( $id=-1,$hash="burkimurki")
        {

            $page_params["refresh_time"] = $this->refresh_time;
            $page_params["refresh_url"]  = base_url().$this->refresh_url;

            if( $id < 1 || $hash == "burkimurki" )
            {
                $page_params["error_message"] = $this->lang->line('request_password_reset_invalid_hash_id');
                $this->load->view($this->view_path.'/rauth/pages/error_view',$page_params);
                return;
            }

            if( !$this->rauth->send_new_password( $id, $hash ))
            {
                $page_params["error_message"] = $this->lang->line('request_password_reset_mail_send_failed');
                $this->load->view($this->view_path.'/rauth/pages/error_view',$page_params);
                return;
            }
            else{
                $page_params["information_message"] = $this->lang->line('request_password_reset_mail_send_success');
                $this->load->view($this->view_path.'/rauth/pages/info_view',$page_params);
            }            
        }

        function approve_user( $id=-1, $hash="burkimurki" )
        {
            $page_params["refresh_time"] = $this->refresh_time;
            $page_params["refresh_url"]  = base_url().$this->refresh_url;

            if( $id < 1 || $hash == "burkimurki" )
            {
                $page_params["error_message"] = $this->lang->line('approve_user_invalid_hash_id');
                $this->load->view($this->view_path.'/rauth/pages/error_view',$page_params);
                return;
            }
            
            if( $this->Ram->activate_user_account($id, $hash) )
            {
                $page_params["error_message"] = $this->lang->line('approve_user_success');
                $page["info_message"] = "Hesabınız aktif edildi. E-posta adresiniz ve parolanız ile oturum açabilirsiniz.";
                $this->load->view($this->view_path.'/rauth/pages/info_view',$page_params);
            }
        }

        
    }

?>
